package www.openteam.com.adapter.qualityCntrl;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.IQCMsg00;

/**
 * Created by OT on 2017-12-15.
 */

public class IQCAdapter extends RecyclerView.Adapter<IQCAdapter.ViewHolder> {


    private Context context;
    private List<IQCMsg00.DataBeanX.DataBean> dataList;
     OnLongClickListener onLongClickListener;

    public void setOnLongClickListener(OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    public void setDataList(List<IQCMsg00.DataBeanX.DataBean> dataList) {
        this.dataList = dataList;
    }

    public IQCAdapter(Context context) {
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_iqc, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        IQCMsg00.DataBeanX.DataBean dataBean = dataList.get(position);
        holder.iqcItemDate.setText(dataBean.getEnterdate());
        holder.iqcItemPurchaseNo.setText(dataBean.getPurchNo());
        holder.iqcItemStockNo.setText(dataBean.getRdsno());
        holder.iqcItemBatchNo.setText(dataBean.getBatchNo());
        holder.iqcItemCode.setText(dataBean.getMaterialCode());
        holder.iqcItemName.setText(dataBean.getMaterialName());
        holder.iqcItemSpecs.setText(dataBean.getSpecs());
        holder.iqcItemUnit.setText(dataBean.getUnit());
        holder.iqcItemPNum.setText(dataBean.getPurchNumb());
        holder.iqcItemCNum.setText(dataBean.getBnumber());
        holder.linearLayout.setBackgroundResource(R.color.green);
        holder.linearLayout.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (onLongClickListener!=null){
                    onLongClickListener.onLongClick(position);
                }
                return false;
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }



    static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iqc00)
        LinearLayout linearLayout;
        @Bind(R.id.iqc_item_date)
        TextView iqcItemDate;
        @Bind(R.id.iqc_item_purchaseNo)
        TextView iqcItemPurchaseNo;
        @Bind(R.id.iqc_item_stockNo)
        TextView iqcItemStockNo;
        @Bind(R.id.iqc_item_batchNo)
        TextView iqcItemBatchNo;
        @Bind(R.id.iqc_item_code)
        TextView iqcItemCode;
        @Bind(R.id.iqc_item_name)
        TextView iqcItemName;
        @Bind(R.id.iqc_item_specs)
        TextView iqcItemSpecs;
        @Bind(R.id.iqc_item_unit)
        TextView iqcItemUnit;
        @Bind(R.id.iqc_item_pNum)
        TextView iqcItemPNum;
        @Bind(R.id.iqc_item_cNum)
        TextView iqcItemCNum;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnLongClickListener{
        void onLongClick(int postion);
    }
}
